package com.xsherl.leetcode.solution;

import com.xsherl.leetcode.base.TreeNode;

public class SameTree {

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null){
            return true;
        }
        if (p == null || q == null){
            return false;
        }
        return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(q.right, p.right);
    }

    public static void main(String[] args) {
        TreeNode p = TreeNode.buildTree(1, 3, 3);
        TreeNode q = TreeNode.buildTree(1, 2, 3);
        boolean sameTree = new SameTree().isSameTree(p, q);
        System.out.println(sameTree);
    }
}
